package cn.angis.flow.adapter;

import cn.angis.flow.vo.WarmFlowInteractiveTypeVo;
import cn.angis.system.dto.output.LoginOutput;
import cn.angis.system.util.AuthUtil;
import org.dromara.warm.flow.core.dto.FlowParams;
import org.dromara.warm.flow.core.enums.CooperateType;
import org.noear.solon.annotation.Component;

import java.util.Objects;

/**
 * 委派适配器
 */
@Component
public class DeputeAdapter extends AbstractWarmFlowAdapter implements WarmFlowAdapter {
    @Override
    public boolean isAdapter(Integer warmFlowType) {
        return Objects.equals(CooperateType.DEPUTE.getKey(), warmFlowType);
    }

    @Override
    public boolean adapter(WarmFlowInteractiveTypeVo obj) {
        Long taskId = obj.getTaskId();
        LoginOutput loginOutput = AuthUtil.getUser();
        String userId = loginOutput.getId();
        FlowParams flowParams = new FlowParams()
                .handler(userId)
                .permissionFlag(permissionList(loginOutput, userId))
                .addHandlers(obj.getAddHandlers())
                .message(this.type(obj.getOperatorType()));

        return super.taskService.depute(taskId, flowParams);
    }
}
